$m(function (args) {
    var $this = this.element;
    var data = args.data;
    var node = args.source;
    var parameters = data.parameters;
    // 当前模块名称
    var currentModelName;
    // 当前模块名称
    var currentModelParam;
    var getMetaData = function () {
        return node.miningnode("getMetaData");
    }
    //对于btn组件中禁止默认打开编辑的表格id集合 熵值法 相似度 典型相关分析 相关系数 偏相关分析
    var btnBanDefaultEdit = ["entropyevaluation_cols", "similaritiesmeasure_self_var", "canonicalcorr_variable", "canonicalcorr_totalObserved",
        "correlationcoefficient_variable", "corrvar", "variableselection_feature"];

    if (args.currentModelName == "subtotal") {
        $("#graph_util_rightzone_columnselect").css("width", "520px")
    }
    /**
     * 初始化对话框
     */
    var initDialog = function () {
        var maindg = args.dialog;
        /**
         * 配置框默认高度: window.constant.MINE_DIALOG_SIZE.BIG.height
         * 配置框默认宽度:    window.constant.MINE_DIALOG_SIZE.BIG.width
         *    如不是，则设置参数param的height和width属性
         * 确认按钮和取消按钮的文本不需要添加，已经处理
         */
        var dialogWidth = window.constant.MINE_DIALOG_SIZE.MAX.width;
        //修改分类汇总配置框宽度
        if (args.currentModelName == "subtotal") {
            dialogWidth = 900;
        }
        if(args.currentModelName == "entropyevaluation"){
            dialogWidth = 1000;
        }
        var param = {
            width: dialogWidth,
            height: window.constant.MINE_DIALOG_SIZE.MAX.height,
            confirm: {
                id: 'tempo-mine-util-savebtn',
                click: function () {
                    //返回true，表示设置完成，需要关闭对话框，否则不关闭
                    return savePagePropertyValue();
                }
            },
            cancel: {
                click: function () {
                    //函数默认为空，需要时自己在js里添加，不要在组件里添加
                    if (!args.currentModelName == "vectorautoreg") {
                        return cancelPagePropertyValue();
                    }
                    //不做任何处理, 一般可以不需要取消函数
                }
            },
            values: parameters
        }
        if (args.addHeight != null) {
            param.height += args.addHeight;
        }
        if (args.currentModelName == "subtotal") {
            param.width = param.width + 70;
        }
        if (args.addWidth != null) {
            param.width += args.addWidth;
        }
        if (args.dialogClass != null) {
            param.dialogClass = args.dialogClass;
        }
        //给fpgrowth节点确定增加撤销回退事件
        if (args.currentModelName == "fpgrowth") {
            //绑定节点确定撤销事件
            param.undo = function (ele, parameters) {
                //根据节点是否勾选输出频繁项集，更新最新的端口
                Eventbus.triggerHandler(addPre("updateScope"), ele, parameters.isfrequentSets)[0];
            };
            //绑定节点确定回退事件
            param.redo = function (ele, parameters) {
                //根据节点是否勾选输出频繁项集，更新最新的端口
                Eventbus.triggerHandler(addPre("updateScope"), ele, parameters.isfrequentSets)[0];
            }
        }
        //初始化配置框
        maindg.init(param);
    }
    var callGridFunction = function (functionName, divClassName) {
        //判断是不是变量选择节点
        if (currentModelName == "variableselection") {//是
            //获取右侧表格数据
            return divClassName.tempo_grid_columns_selected_with_btn(functionName);
        } else if (currentModelName == "entropyevaluation") {// 判断是不是熵值法
            return divClassName.tempo_grid_columns_selected_with_btn(functionName);
        } else {//其他节点
            return divClassName.grid_columns_selected_with_btn(functionName);
        }

    }

    /**
     * 点击确定，页面保存方法 ---公共的
     */
    var savePagePropertyValue = function () {
        //页面校验
        if (!validForm()) {
            return false;
        }
        // 保存当前选择的列信息
        var curMedata = getMetaData();
        if (!args.rightParams.notSavePreMeta) {
            parameters.preMetadata = curMedata;
        }
        parameters.metadata = curMedata;
        // 保存右侧表格id
        var ids = [];
        parameters.gridData = {};
        var rightZone = args.rightParams.rightZone;
        for (var i = 0; i < rightZone.length; i++) {
            // 若右侧区域为自定义界面，则直接跳过
            if (rightZone[i].type && rightZone[i].type == "udfElement") {
                continue;
            }
            var id = rightZone[i].id;
            var grid = args.zoneCache[id];
            if (btnBanDefaultEdit.indexOf(id) > -1) {
                var dataObj = {};
                //判断节点是否是带有分页效果的节点
                if (currentModelName == "variableselection" || currentModelName == "entropyevaluation") {
                    //保存表格里正在修改的行数据
                    callGridFunction("saveCurrentEditRow", grid);
                    //获取选中框里的值
                    dataObj.rowDatas = callGridFunction("getAllData", grid);
                } else {
                    //获取选中框里的值
                    dataObj.rowDatas = callGridFunction("getAllEditOrDataFunction", grid);
                }
                var udfModelList = rightZone[i].udfColsModel;
                var editVlist = [];//meta最后添加的编辑的值
                $.each(udfModelList, function (i, v) {
                    if (v.edittype != null) {
                        editVlist.push(v.name);
                    }
                });
                var saveMetaList = [];
                $.each(dataObj.rowDatas, function (i, v) {
                    var node = [v.desc, v.name, v.type, v.role];
                    for (var j = 0; j < editVlist.length; j++) {
                        node.push(v[editVlist[j]]);
                    }
                    saveMetaList.push(node);
                });
                dataObj.savedMeta = saveMetaList;
                parameters[id] = dataObj.savedMeta;
                // 前台展示的表格数据
                parameters.gridData[id] = dataObj.rowDatas;
            } else {
                // 为了去除分类汇总的分页
                var dataObj;
                if (id == "subtotal_countCol") {
                    //先保存编辑行
                    var gridT = callGridFunction("getGridTable", grid);
                    var lastId = gridT.datagrid("getLastEditId");
                    gridT.datagrid("saveRow", lastId);
                    dataObj = callGridFunction("getRowData", grid);
                    // 后台需要解析的表格数据
                    parameters[id] = dataObj;
                    // 前台展示的表格数据
                    parameters.gridData[id] = dataObj;
                } else if (id == "groupline_x") {
                    dataObj = {};
                    var gridT = callGridFunction("getGridTable", grid);
                    var lastId = gridT.datagrid("getLastEditId");
                    gridT.datagrid("saveRow", lastId);
                    dataObj["rowDatas"] = callGridFunction("getRowData", grid);
                    // 后台需要解析的表格数据
                    parameters[id] = dataObj.rowDatas;
                    // 前台展示的表格数据
                    parameters.gridData[id] = dataObj.rowDatas;
                } else {
                    dataObj = callGridFunction("getEditRowData", grid);
                    // 后台需要解析的表格数据
                    parameters[id] = dataObj.savedMeta;
                    // 前台展示的表格数据
                    parameters.gridData[id] = dataObj.rowDatas;
                }
            }
            ids.push(id);
        }
        parameters.joinCol = $this.find('#subtotal_joinCol_join').is(':checked');
        if (parameters.joinCol == false) {
            parameters.gridData["subtotal_joinCol"] = [];
            parameters["subtotal_joinCol"] = []
        }
        parameters.gridIds = ids;
        // 调用当前模块的保存方法，保存其他属性
        Eventbus.triggerHandler(addPre("savePagePropertyValue"))[0];
        return true;
    }

    /**
     * 点击取消，页面取消方法 ---公共的
     */
    var cancelPagePropertyValue = function () {
        //判断右侧的值是否存在。第一次进入时是不存在的
        if (parameters && parameters.gridIds && parameters.gridIds.length) {
            //将右侧两个框的数据进行还原
            var len = parameters.gridIds.length;
            for (var i = 0; i < len; i++) {
                var oldSelectDataId = "oldSelectData_" + parameters.gridIds[i];
                parameters[parameters.gridIds[i]] = parameters[oldSelectDataId];
            }
        }
        // 调用当前模块的取消方法，取消保存的属性
        Eventbus.triggerHandler(addPre("cancelPagePropertyValue"))[0];
    }

    /**
     * 点击确定，页面校验方法
     */
    var validForm = function () {
        // 循环校验右侧列选择区域是否允许为空，若不允许，则校验
        var rightZone = args.rightParams.rightZone;
        var paramss = {}
        //获取是否拼接
        var joinFlag = $this.find('#subtotal_joinCol_join').is(':checked');
        for (var i = 0; i < rightZone.length; i++) {
            var id = rightZone[i].id;
            //没有选择拼接，则不去校验
            if (id == "subtotal_joinCol" && !joinFlag) {
                continue;
            }
            var grid = args.zoneCache[id];
            var rowDatas;
            // 如果是分类汇总使用不分页的方法
            if (id.indexOf("subtotal") != -1) {
                rowDatas = grid.grid_columns_selected_with_btn("getAllEditOrDataFunction");
            } else {
                rowDatas = grid.tempo_grid_columns_selected_with_btn("getAllEditOrDataFunction");
            }
            var udfModelList = rightZone[i].udfColsModel;
            var editVlist = [];//meta最后添加的编辑的值
            $.each(udfModelList, function (i, v) {
                if (v.edittype != null) {
                    editVlist.push(v.name);
                }
            });
            var saveMetaList = [];
            $.each(rowDatas, function (i, v) {
                var node = [v.desc, v.name, v.type, v.role];
                for (var j = 0; j < editVlist.length; j++) {
                    node.push(v[editVlist[j]]);
                }
                saveMetaList.push(node);
            });
            paramss[id] = saveMetaList;
            // 若右侧区域为自定义界面，则直接跳过
            if (rightZone[i].type && rightZone[i].type == "udfElement") {
                continue;
            }
            var currentZone = args.zoneCache[rightZone[i].id];
            var datas = {};
            //判断带有分页的节点 变量选择第一个框是分页框  熵值法第二框是分页框
            if (id == "variableselection_feature" || id == "entropyevaluation_cols") {
                // 先保存
                callGridFunction("saveCurrentEditRow", currentZone);
                // 在获取分页组件的全部数据
                datas.rowDatas = callGridFunction("getAllData", currentZone);
            } else {
                datas.rowDatas = callGridFunction("getRowData", currentZone);
            }

            // 校验当前列是否被修改或删除
            var fieldErrorMap = callGridFunction("getFieldErrorMap", currentZone);
            for (var j = 0; j < datas.rowDatas.length; j++) {
                if(args.currentModelName == "entropyevaluation"){
                    break;
                }
                var errorMap = fieldErrorMap.get(datas.rowDatas[j].desc);
                // modify 2022-11-14 limy 对平行坐标图做特殊处理
                // 如果为平行坐标图，校验规则为desc+name+type，true表识是错误的
                if (id == "parallelcoordinates_x" || id == "parallelcoordinates_y") {
                    // 如果有错误字段信息，并且类型一致，注释名一致，代表是有错误字段，不应该跳过，否则跳过
                    if (!(errorMap && errorMap.meta.type == datas.rowDatas[j].type && errorMap.meta.name == datas.rowDatas[j].name)) {
                        continue;
                    }
                } else {
                    // 如果有错误信息，并且类型一致，代表是有错误字段，不应该跳过，否则跳过
                    if (!(errorMap && errorMap.meta.type == datas.rowDatas[j].type)) {
                        continue;
                    }
                }
                var errorInfo = TempoMineMetaUtils.getTypeChangedTip();
                if (errorMap.reason == "name") {
                    //该字段已被前置节点删除！
                    errorInfo = TempoMineMetaUtils.getFieldNotExistsTip();
                }else if(errorMap.reason == "idColumn"){
                    //该字段已被设置为ID列!
                    errorInfo =TempoUtils.locale("mine.meta_field_set_id_column");
                }
                //报错弹窗
                $("<div/>").alert({
                    msg: datas.rowDatas[j].desc + ":" + errorInfo,
                    title: TempoUtils.locale("mine.prompt")
                });
                return false;
            }
            if (rightZone[i].allowNull) {
                continue;
            }
            if (rightZone[i].isNotValidNull && rightZone[i].isNotValidNull == true) {

            } else {
                if (!currentZone || datas.rowDatas.length == 0) {
                    $("<div/>").alert({
                        //解决52241校验提示信息问题
                        msg: TempoUtils.locale("mine.parameterNotNull"),
                        title: TempoUtils.locale("mine.prompt")
                    });
                    return false;
                }
            }
        }

        //开启拼接，需要校验拼接字段是否全包含分组字段
        if (joinFlag) {
            if (paramss.subtotal_splitCol.length == 0) {
                $("<div/>").alert({
                    msg: TempoUtils.locale("subtotal.nogroupcolumn"),
                    title: TempoUtils.locale("mine.prompt")
                });
                return false;
            }
            if (paramss.subtotal_joinCol.length == 0) {
                $("<div/>").alert({
                    msg: TempoUtils.locale("subtotal.nojoincolumn"),
                    title: TempoUtils.locale("mine.prompt")
                });
                return false;
            }
        }
        // 调用当前模块的校验方法
        var flag = Eventbus.triggerHandler(addPre("validForm"), args.zoneCache)[0];
        return flag;
    }

    /**
     * 初始化列操作区域，并赋值
     */
    var initColumnSelectZone = function () {
        // 若自定义了高度，则修改顶部区域的高度
        if (currentModelParam && currentModelParam.rightZoneHeight) {
            $("#graph_util_topzone").height(currentModelParam.rightZoneHeight);
            $this.find("#graph_util_rightzone_columnselect").height(currentModelParam.rightZoneHeight);
        }
        // 设置左右居于同一行，在js中设置会出现弹出框大小被改变的问题
        var leftColumnSelect = $this.find("#graph_util_leftzone_columnselect");
        leftColumnSelect.css({"float": "left"});
        $this.find("#graph_util_rightzone_columnselect").css({"float": "left"});
        // 初始化左侧待选区域
        initLeftZone(leftColumnSelect);
        // 初始化右侧已选区域
        initRightZone(leftColumnSelect);
        //分类汇总中新增中间的下拉框
        if (args.currentModelName == "subtotal") {
            $this.find("#graph_util_rightzone_columnselect").width(590);
            initSelect();//初始化下拉框
        }
        if (args.currentModelName == "entropyevaluation") {
            initSelect2();
        }
    }
    var isNumber = function (val) {
        val = val.replace(/\s+/g,'');
        var regPos = /^(-?\d+)(.\d+)?$/;
        if(regPos.test(val)){
            return true;
        }else {
            return false;
        }
    }
    var initSelect2 = function () {
        if(parameters.gridData){
            for (var i = 0; i < parameters.gridData.entropyevaluation_cols.length; i++) {
                if(parameters.gridData.entropyevaluation_cols[i].policy == undefined){
                    parameters.gridData.entropyevaluation_cols[i].policy = "0";
                }
            }
        }
        var $position = $this.find('#entropyevaluation_cols');
        var str = "<span>";
        str += "<label style='margin-left:90px'>" + TempoUtils.locale("entropyevaluation.batch") + "</label>";
        str += "&nbsp;&nbsp;&nbsp;&nbsp;";
        str += "<select id='entropyevaluationSelect'>";
        str += "<option value='1'>" + TempoUtils.locale("entropyevaluation.maxAttsCols") + "</option>";
        str += "<option value='0'>" + TempoUtils.locale("entropyevaluation.minAttsCols") + "</option>";
        str += "<option value='2'>" + TempoUtils.locale("entropyevaluation.AmongTheOptimal") + "</option>";
        str += "<option value='3'>" + TempoUtils.locale("entropyevaluation.IntervalOfTheOptimal") + "</option>";
        str += "</select>";
        str += "</span>";
        $(str).insertBefore($position);
        $this.find('#entropyevaluation_cols').css('margin-top', '8px');
        $this.find("#entropyevaluationSelect").selectmenu({
            width: 90,
            select: function (e, ui) {
                var grid = args.zoneCache['entropyevaluation_cols'];
                //获取批量下拉框的值
                var bestdirectionVal = ui.item.value;
                //获取jqGrid的GridTable对象
                var gridTable = callGridFunction("getGridTable", grid);
                //批量设置当前页选中的数据中的某一字段的值
                grid.tempo_grid_columns_selected_with_btn("batchSyncData", gridTable, "bestdirection", bestdirectionVal);
                if(currentModelName == "entropyevaluation"){
                    var checkrows = gridTable.find('input[type="checkbox"]:checked');//所有被选择的元素
                    //获取最优方向列
                    var allmodify = checkrows.closest('tr').find('td[aria-describedby$="bestdirection"]');
                    //获取最大最小值策略列
                    var policyList = checkrows.closest('tr').find('td[aria-describedby$="policy"]');
                    //获取值列
                    var policyValueList = checkrows.closest('tr').find('td[aria-describedby$="value"]');
                    //获取最优区间/值列
                    var  intervalList= checkrows.closest('tr').find('td[aria-describedby$="interval"]');
                    allmodify.attr('title',ui.item.label);
                    policyList.attr('title',TempoUtils.locale("entropyevaluation.automatic"));
                    //被选中的最优方向
                    var editting = checkrows.closest('tr').find('td[aria-describedby$="bestdirection"] select[id$="_bestdirection"]');
                    //被选中的最大最小值策略
                    var maximumPolicy = checkrows.closest('tr').find('td[aria-describedby$="policy"] select[id$="_policy"]');
                    for(var i = 0; i < editting.length; i++){
                        $(editting[i]).selectmenu("setValue",ui.item.value);
                    }
                    for(var i = 0; i < maximumPolicy.length; i++){
                        $(maximumPolicy[i]).selectmenu("setValue","1");
                    }
                    for(var i = 0; i < allmodify.length; i++){
                        var $temp = $(allmodify[i]);
                        if($temp.find("select").length == 0){
                            $temp.text(ui.item.label);
                        }
                    }
                    if(ui.item.label == TempoUtils.locale("entropyevaluation.big") || ui.item.label == TempoUtils.locale("entropyevaluation.small") ){
                        for(var i = 0; i < policyList.length; i++){
                            var $policyList = $(policyList[i]);
                            if($policyList.find("select").length == 0){
                                $policyList.text(TempoUtils.locale("entropyevaluation.automatic"));
                            }
                        }
                    }
                    if(ui.item.label == TempoUtils.locale("entropyevaluation.AmongTheOptimal")){
                        for(var i = 0; i < policyList.length; i++){
                            var $policyList = $(policyList[i]);
                            if($policyList.find("select").length == 0){
                                $policyList.text(TempoUtils.locale("entropyevaluation.custom"));
                            }
                        }
                    }
                    if(ui.item.label == TempoUtils.locale("entropyevaluation.IntervalOfTheOptimal")){
                        for(var i = 0; i < policyList.length; i++){
                            var $policyList = $(policyList[i]);
                            if($policyList.find("select").length == 0){
                                $policyList.text(TempoUtils.locale("entropyevaluation.custom"));
                            }
                        }
                        for(var i = 0; i < policyValueList.length; i++){
                            var $policyValueList = $(policyValueList[i]);
                            if($policyValueList.find("input").length == 0){
                                $policyValueList.find("input").attr("placeholder","0,100")
                            }
                        }
                        for(var i = 0; i < intervalList.length; i++){
                            var $intervalList = $(intervalList[i]);
                            if($intervalList.find("input").length == 0){
                                $intervalList.find("input").attr("placeholder","40,60")
                            }
                        }
                    }
                    for (var i = 0; i < checkrows.length; i++) {
                        $(checkrows[i]).parent().parent().find('td[aria-describedby$="value"]').validatebox({readonly: true});
                        $(checkrows[i]).parent().parent().find('td[aria-describedby$="interval"]').validatebox({readonly: true});
                        $(checkrows[i]).parent().parent().find('td[aria-describedby$="value"]').attr("disabled","");
                        $(checkrows[i]).parent().parent().find('td[aria-describedby$="interval"]').attr("disabled","");
                        if($(checkrows[i]).parent().parent().find('td[aria-describedby$="value"]').text() != ""){
                            $(checkrows[i]).parent().parent().find('td[aria-describedby$="value"]').text('');
                            $(checkrows[i]).parent().parent().find('td[aria-describedby$="interval"]').text('');
                            $(checkrows[i]).parent().parent().find('td[aria-describedby$="value"]').attr("title",'');
                            $(checkrows[i]).parent().parent().find('td[aria-describedby$="interval"]').attr("title",'');
                        }
                    }
                }
                for (var i = 0; i < checkrows.length; i++) {
                    // 调用展示默认值方法
                    Eventbus.triggerHandler(addPre("displaceholder"),$(checkrows[i]).parent().parent().attr("id"),gridTable)[0];
                }
            }
        });
        if (parameters.subSelectVal != null) {
            $this.find("#entropyevaluationSelect").selectmenu("setValue", parameters.entropyevaluationSelect);
        }
    }
    /**
     * 初始化下拉框
     */
    var initSelect = function () {
        var $position = $this.find('#subtotal_countCol');
        var $rightDiv = $this.find('#graph_util_rightzone_columnselect');
        var $joinCol = $this.find('#subtotal_joinCol');
        var join = "<input type='checkbox' id='subtotal_joinCol_join' ui-role='checkbox' class='tempo-checkbox'/>" +
            "<label for='subtotal_joinCol_join' style='margin-left: 90px'>" + TempoUtils.locale("subtotal.joinCol") + "</label><span class='customFormat-helpIcon' " +
            "title='是否将原表数据与汇总结果进行拼接，分组字段作为连接字段'></span><select id='subtotalSelect' style='visibility: hidden;' class='tempo-selectmenu'></select>";
        $(join).insertBefore($joinCol);
        $this.find('#subtotal_joinCol_join').unbind('click').bind('click', function () {
            if ($(this).is(':checked')) {
                $joinCol.css('visibility', 'inherit');
            } else {
                $joinCol.css('visibility', 'hidden');
            }
        });
        if (parameters.joinCol) {
            $this.find('#subtotal_joinCol_join').trigger('click');
        } else {
            $joinCol.css('visibility', 'hidden');
        }
        var str = "<span>";
        str += "<label style='margin-left:90px'>" + TempoUtils.locale("subtotal.batchnum") + "</label>";
        str += "&nbsp;&nbsp;&nbsp;&nbsp;";
        str += "<select id='subtotalSelect'>";
        str += "<option value='count_val'>" + TempoUtils.locale("subtotal.count_val") + "</option>";
        str += "<option value='max_val'>" + TempoUtils.locale("subtotal.max_val") + "</option>";
        str += "<option value='min_val'>" + TempoUtils.locale("subtotal.min_val") + "</option>";
        str += "<option value='avg_val'>" + TempoUtils.locale("subtotal.avg_val") + "</option>";
        str += "<option value='sum_val'>" + TempoUtils.locale("subtotal.sum_val") + "</option>";
        str += "<option value='var_samp_val'>" + TempoUtils.locale("subtotal.var_samp_val") + "</option>";
        str += "<option value='stddev_samp_val'>" + TempoUtils.locale("subtotal.stddev_samp_val") + "</option>";
        str += "<option value='countDistinct_val'>" + TempoUtils.locale("subtotal.countDistinct_val") + "</option>";
        str += "<option value='upQuartile'>" + TempoUtils.locale("subtotal.upQuartile") + "</option>";
        str += "<option value='downQuartile'>" + TempoUtils.locale("subtotal.downQuartile") + "</option>";
        str += "<option value='median'>" + TempoUtils.locale("subtotal.median") + "</option>";
        str += "<option value='cv_val'>" + TempoUtils.locale("subtotal.cv_val") + "</option>";
        str += "<option value='udfQuantile'>" + TempoUtils.locale("subtotal.percentile") + "</option>";
        str += "</select>";

        str += "<label id='subtotalValueLabel' style='margin-left:10px'>" + TempoUtils.locale("subtotal.value") + "</label>";
        str += "&nbsp;&nbsp;&nbsp;&nbsp;";
        str += "<input type='text' id='subtotalValue' name='subtotalValue' ui-role='validatebox' style='padding-bottom: 2px;'/>";

        str += "<label id='subtotalStrSelecLabel' style='margin-left:103px'>" + TempoUtils.locale("subtotal.batchStr") + "</label>";
        str += "&nbsp;&nbsp;&nbsp;&nbsp;";
        str += "<select id='subtotalStrSelec'>";
        str += "<option value='count_val'>" + TempoUtils.locale("subtotal.count_val") + "</option>";
        str += "<option value='countDistinct_val'>" + TempoUtils.locale("subtotal.countDistinct_val") + "</option>";
        str += "</select>";

        str += "</span>";
        $(str).insertBefore($position);
        //增加近似计算和精准计算
        var str1 = "<div class='tempo-mine-dp-subtotal-right-bottom-radios' style='float: right;margin-left: 0px;margin-top: -110px;'>";
        //近似计算
        str1 += "<input type='radio' id='approximate-subtotal' class='tempo-radio' name='subtotal-way-set' checked='checked'/>";
        str1 += "<label for='approximate-subtotal'>近似计算</label>";
        //精准计算
        str1 += "<input type='radio' id='precision-subtotal' class='tempo-radio' name='subtotal-way-set'/>";
        str1 += "<label for='precision-subtotal' style='margin-left: 20px'>精准计算</label>";
        str1 += "<span id='disInfoSubtotal' class='ui-icon tempo-ui-icon tempo-ui-icon-tip tempo-mine-button' style='margin-left: 10px;'></span>";
        str1 += "</div>";
        $(str1).insertAfter($rightDiv);
        //增加提示框
        var helpInfo = "<div id='helpInfoSubtotal' style='background: rgb(243, 245, 247);" +
            "position:absolute;position:absolute;width:200px;height:35px;backgroud:#e0e5e5;" +
            "box-shadow:0px 0px 10px rgb(46, 49, 53);z-index:99999;text-align: center;'>" + TempoUtils.locale("subtotal.helpInfo") + "</div>";
        //判断只初始化一次
        if ($("#helpInfoSubtotal").length == 0) {
            $('body').append(helpInfo);
        }

        $("#helpInfoSubtotal").hide();
        $("#disInfoSubtotal").mouseover(function () {

            var x = $("#disInfoSubtotal").offset().left;
            var y = $("#disInfoSubtotal").offset().top;
            $("#helpInfoSubtotal").css("left", x + 20);
            $("#helpInfoSubtotal").css("top", y + 20);

            $("#helpInfoSubtotal").show();
        })
        $("#disInfoSubtotal").mouseout(function () {
            $("#helpInfoSubtotal").hide();
        })

        $this.find('#subtotal_countCol').css('margin-top', '2px');
        $this.find("#subtotalValue").validatebox({
            width: '40px'
        });
        //只有当选择为百分位数时才展示
        $this.find("#subtotalValueLabel").hide();
        $this.find("#subtotalValue").hide();
        $this.find("#subtotalValue").off("focusout").on("focusout", function () {
            var value = $this.find("#subtotalValue").val();
            var rule = /^[1-9][0-9]?$/;
            var nustr = TempoUtils.locale("mine.meta_fields_label_number");
            if (value == "") {
                return false;
            } else {
                if (!rule.test(value)) {
                    showTip(TempoUtils.locale("subtotal.valueError"));
                    return false;
                }
            }
            var grid = args.zoneCache['subtotal_countCol'];
            var checkrows = grid.find('input[type="checkbox"]:checked');//所有被选择的元素
            if (checkrows && checkrows.length <= 0) {
                return false;
            }
            //先把所有被选中的行保存,如果不保存，text和attr会把组件一起渲染掉
            var gridTable = callGridFunction("getGridTable", grid);
            var length = callGridFunction("getAllEditOrDataFunction", grid).length;
            for (var i = 1; i <= length; i++) {
                gridTable.datagrid('saveRow', i);
            }
            var allmodify = checkrows.closest('tr').find('td[aria-describedby$="type"][title^=' + nustr + ']').next().next();
            allmodify.text(value);
            allmodify.attr('title', value);
            var allGridData = callGridFunction("getAllEditOrDataFunction", grid);
            for (var i = 0; i < allGridData.length; i++) {
                var calcFunc = allGridData[i].calcFunc;
                if (calcFunc != "udfQuantile") {
                    var tdInput = gridTable.find("tr[id=" + (i + 1) + "]").find('td[aria-describedby$="value"]');
                    tdInput.text("");
                    tdInput.attr('title', "");
                }
            }
        });

        $this.find("#subtotalStrSelec").selectmenu({
            width: 90,
            select: function (e, ui) {
                var grid = args.zoneCache['subtotal_countCol'];
                var nustr = TempoUtils.locale("mine.meta_fields_label_char");
                //获取所有被选择的元素
                var checkrows = grid.find('input[type="checkbox"]:checked');
                if (checkrows && checkrows.length <= 0) {
                    showTip(TempoUtils.locale("subtotal.selectnull"));
                    return false;
                }
                //先把所有被选中的行保存,如果不保存，text和attr会把组件一起渲染掉
                var gridTable = grid.grid_columns_selected_with_btn("getGridTable");
                var rowIds = gridTable.datagrid("getRowIds");
                for (var i = 0; i <= rowIds.length-1; i++) {
                    if(rowIds[i]){
                        gridTable.datagrid('saveRow', rowIds[i]);
                    }else{
                        gridTable.datagrid('saveRow', parseInt(i)+1);
                    }
                }
                var allmodify = checkrows.closest('tr').find('td[aria-describedby$="type"][title^=' + nustr + ']').next().next();
                allmodify.text(ui.item.label);
                allmodify.attr('title', ui.item.label);
            }
        });

        $this.find("#subtotalSelect").selectmenu({
            width: 110,
            select: function (e, ui) {
                var grid = args.zoneCache['subtotal_countCol'];
                var nustr = TempoUtils.locale("mine.meta_fields_label_number");
                if (ui.item.value == "udfQuantile") {
                    $this.find("#subtotalValueLabel").show();
                    $this.find("#subtotalValue").show();
                    $this.find("#subtotalStrSelecLabel").css('margin-left', '22px');
                } else {
                    $this.find("#subtotalValueLabel").hide();
                    $this.find("#subtotalValue").hide();
                    $this.find("#subtotalStrSelecLabel").css('margin-left', '103px');
                }
                var checkrows = grid.find('input[type="checkbox"]:checked');//所有被选择的元素
                if (checkrows && checkrows.length <= 0) {
                    showTip(TempoUtils.locale("subtotal.selectnull"));
                    return false;
                }
                //先把所有被选中的行保存,如果不保存，text和attr会把组件一起渲染掉
                var gridTable = grid.grid_columns_selected_with_btn("getGridTable");
                var rowIds = gridTable.datagrid("getRowIds");
                for (var i = 0; i <= rowIds.length-1; i++) {
                    if(rowIds[i]){
                        gridTable.datagrid('saveRow', rowIds[i]);
                    }else{
                        gridTable.datagrid('saveRow', parseInt(i)+1);
                    }
                }
                var allmodify = checkrows.closest('tr').find('td[aria-describedby$="type"][title^=' + nustr + ']').next().next();
                allmodify.text(ui.item.label);
                allmodify.attr('title', ui.item.label);
                if (ui.item.value != "udfQuantile") {
                    var allbaifenweishuData = checkrows.closest('tr').find('td[aria-describedby$="type"][title^=' + nustr + ']').next().next().next();
                    allbaifenweishuData.text("");
                    allbaifenweishuData.attr('title', "");
                }
                var s = callGridFunction("getAllEditOrDataFunction", grid);

                var jisuanWay = $('input[name=subtotal-way-set]:checked').attr('id');
                //中位数或者百分位数显示近似计数和精准计数
                if (ui.item.value == "udfQuantile" || ui.item.value == "median" || ui.item.value == "upQuartile" || ui.item.value == "downQuartile") {
                    $(".tempo-mine-dp-subtotal-right-bottom-radios").show();
                    $('#' + jisuanWay).radio({
                        checked: true,
                    });
                } else {
                    var newGridDate = callGridFunction("getAllEditOrDataFunction", grid);
                    for (var i = 0; i < newGridDate.length; i++) {
                        var newCalcFunc = newGridDate[i].calcFunc;
                        if (newCalcFunc == "udfQuantile" || newCalcFunc == "median" || ui.item.value == "upQuartile" || ui.item.value == "downQuartile") {
                            $(".tempo-mine-dp-subtotal-right-bottom-radios").show();
                            $('#' + jisuanWay).radio({
                                checked: true,
                            });
                            break;
                        }
                        $(".tempo-mine-dp-subtotal-right-bottom-radios").hide();
                        $('#approximate-subtotal').radio({
                            checked: true,
                        });
                    }
                }
            }
        });
        if (parameters.subSelectVal != null) {
            $this.find("#subtotalSelect").selectmenu("setValue", parameters.subSelectVal);
        }
        if (parameters.subSelectStrVal != null) {
            $this.find("#subtotalStrSelec").selectmenu("setValue", parameters.subSelectStrVal);
        }
        if (parameters.subSelectVal != null && parameters.subSelectVal == "udfQuantile") {
            $this.find("#subtotalValueLabel").show();
            $this.find("#subtotalValue").show();
            $this.find("#subtotalStrSelecLabel").css('margin-left', '22px');
        }
    }
    var showTip = function (_msg) {
        $("<div/>").alert({
            msg: _msg,
            title: TempoUtils.locale("setrole.prompt")
        });
    }
    /**
     * 左侧待选列区域初始化
     */
    var initLeftZone = function (leftColumnSelect) {
        var metadata = getMetaData();
        // 得到所有已选的字段名的数组
        var chooseDatas = TempoMineMetaUtils.getChoosedDatas(parameters.gridData);
        // 加载待选列
        var liDataSet = [];
        //存在数据
        if (metadata && metadata.length > 0) {
            for (var i = 0; i < metadata.length; i++) {
                var obj = TempoMineMetaUtils.convertMetaToObj(metadata[i]);
                // 将已选到右侧列过滤掉
                if (args.rightParams.leftTreeChangeable == false) {

                } else {
                    // 修改变量选择左侧展示通过desc+类型进行判断
                    if (args.currentModelName == "variableselection" && chooseDatas.descs.indexOf(obj.desc) > -1 && chooseDatas.types[chooseDatas.descs.indexOf(obj.desc)] == obj.type ) {
                        continue;
                    }
                    if (chooseDatas.names.indexOf(obj.name) > -1 && chooseDatas.types[chooseDatas.names.indexOf(obj.name)] == obj.type && chooseDatas.descs.indexOf(obj.desc) > -1) {
                        continue;
                    }
                    //如果节点是向量自回归，过滤调数据中的ID列
                    if (currentModelName && currentModelName == "vectorautoreg") {
                        if (obj.role == window.constant.MINE_DATA_ROLE.ID) {
                            continue;
                        }
                    }
                }

                liDataSet.push(obj);
            }
        }
        var showRadios = [];
        if (currentModelParam.showRadios) {
            showRadios = currentModelParam.showRadios;
        }
        // 初始化左侧框
        if (currentModelName == "variableselection" || currentModelName == "subtotal" || currentModelName == "entropyevaluation") {
            leftColumnSelect.mine_columnselect({
                data: liDataSet,
                width: "275px",
                height: "100%",
                hideToolBar: true,
                showRadios: showRadios,
                pagesize: 20,
                pagination: true,
            });
            leftColumnSelect.find(".tempo-mine-column-list").css("overflow", "auto");
            leftColumnSelect.find("#columnPage").css("position", "absolute").css("width", "235px");
        } else {
            leftColumnSelect.columnselect({
                data: liDataSet,
                width: "275px",
                height: "100%",
                hideToolBar: true,
                showRadios: showRadios,
                pagesize: 20,
                pagination: true,
            });
        }
    }

    /**
     * 得到所有已选的字段名与类型的数组
     */
    var getChoosedDatas = function () {
        if (!parameters.gridData) {
            return {"names": [], "types": []};
        }
        var names = [];
        var types = [];
        for (var key in parameters.gridData) {
            var rowData = parameters.gridData[key];
            for (var i = 0; i < rowData.length; i++) {
                names.push(rowData[i].desc);
                types.push(rowData[i].type)
            }
        }
        return {"names": names, "types": types};
    }

    /**
     * 右侧已选区域初始化 --公共的
     */
    var initRightZone = function (leftColumnSelect) {
        // 若rightZone列表为空，则直接返回
        if (!currentModelParam || !currentModelParam.rightZone || currentModelParam.rightZone.length == 0) {
            return;
        }
        var rightGrids = currentModelParam.rightZone;
        var totalHeight = $("#graph_util_topzone").height();
        // totalHeight-23为左侧待选区域的高度，27为列表表头的高度，35为fieldset的边框
        var avgHeight = (totalHeight - 7) / rightGrids.length;
        if (currentModelParam.rightZone.fieldset && currentModelParam.rightZone.fieldset.show) {
            avgHeight = avgHeight - 35;
        }
        // 当前元信息
        var metadata = getMetaData();
        for (var i = 0; i < rightGrids.length; i++) {
            addGridZoneToPanel(metadata, rightGrids[i], avgHeight, $this.find("#graph_util_rightzone_columnselect_table"), leftColumnSelect);
        }
    }

    /**
     * 根据传入的参数，生成grid_columns_selected_with_btn组件，并添加至父容器上 --公共的
     */
    var addGridZoneToPanel = function (metadata, zoneParam, height, parantEle, leftColumnSelect) {
        //传递字段信息，包括该字段的错误信息
        var rowDatas = [];
        if (parameters.gridData && parameters.gridData[zoneParam.id]) {
            rowDatas = $.extend(true, [], parameters.gridData[zoneParam.id]);
        }
        if (!zoneParam.udfContextColLabels) {
            zoneParam.udfContextColLabels = {};
        }
        var td = $("<td/>");
        var tr = $("<tr/>");
        td.appendTo(tr);
        tr.appendTo(parantEle);
        var thisZone = $("<div id='" + zoneParam.id + "'/>").appendTo(td);
        var udfColsModel = [];
        // 自定义coleModel
        if (zoneParam.udfColsModel) {
            udfColsModel = zoneParam.udfColsModel;
        }
        // 自定义colLabel
        var udfColLabels = [];
        if (zoneParam.udfColLabels) {
            udfColLabels = zoneParam.udfColLabels;
        }
        // 自定义接收类型
        var allowTypes = [];
        if (zoneParam.allowTypes) {
            allowTypes = zoneParam.allowTypes;
        }
        // 自定义列表可接收的最大数据量
        var gridMaxData = 1;
        if (zoneParam.gridMaxData) {
            gridMaxData = zoneParam.gridMaxData;
        }
        // 自定义隐藏类型
        var contextHiddenColNames = ["desc", "type"];
        if (zoneParam.contextHiddenColNames) {
            contextHiddenColNames = zoneParam.contextHiddenColNames;
        }
        var defaultWidth = ["20px", "75px", "75px", "77px"];
        if (zoneParam.defaultWidth) {
            defaultWidth = zoneParam.defaultWidth;
        }
        var uniquefield = false;
        if (zoneParam.uniquefield) {
            uniquefield = zoneParam.uniquefield;
        }
        var directToEdit = {inEditDirect: false};
        if (zoneParam.directToEdit && Object.keys(zoneParam.directToEdit).length > 0) {
            directToEdit = zoneParam.directToEdit;
        }
        var removeDup = false;
        if (zoneParam.removeDup) {
            removeDup = zoneParam.removeDup;
        }
        var multEdit = false;
        if (zoneParam.multEdit) {
            multEdit = zoneParam.multEdit;
        }
        //自定义width
        var width = 405;//之前的版本就是405 这里保持不变
        if (zoneParam.width) {
            width = zoneParam.width;
        }
        // 若type不是udfElement（自定义界面），则初始化为表格
        if (!zoneParam.type || zoneParam.type != "udfElement") {
            // 自定义高度
            if (zoneParam.height) {
                height = zoneParam.height;
            }
            height = height - 40;
            //初始化表格
            //判断是否是带有分页效果的节点
            if (currentModelName == "variableselection" || currentModelName == "entropyevaluation") {
                //保存原始数据，可能有多个，使用每个框id保存
                var oldSelectDataId = "oldSelectData_" + zoneParam.id;
                parameters[oldSelectDataId] = rowDatas;
                //是带有分页效果的节点
                thisZone.tempo_grid_columns_selected_with_btn({
                    "width": width,
                    "height": ("variableselection_label" == zoneParam.id || "entropyevaluation_goal" == zoneParam.id) ? height : height - 40,
                    "pendingDiv": leftColumnSelect,
                    "contextMeta": metadata, //上下文字段信息列表
                    "udfContextColLabels": zoneParam.udfContextColLabels,
                    "contextHiddenColNames": contextHiddenColNames,//将字段名和类型隐藏
                    "rowsData": rowDatas,
                    "udfColLabels": udfColLabels,
                    "udfColsModel": udfColsModel,
                    "parentDialog": $this,
                    "fieldset": zoneParam.fieldset,
                    "allowTypes": allowTypes,
                    "gridMaxData": gridMaxData,
                    "uniquefield": uniquefield,//针对同一个字段进行处理
                    "removeDup": removeDup,
                    isRendercboxClass: true,
                    directToEdit: directToEdit,
                    multEdit: multEdit,
                    pagination: ("variableselection_label" == zoneParam.id || "entropyevaluation_goal" == zoneParam.id) ? false : true,
                    showBtn: TempoMineUtils.canEdit(args.data.formEditable),
                    editable: TempoMineUtils.canEdit(args.data.formEditable),
                    defaultWidth: defaultWidth,
                    leftTreeChangeable: args.rightParams.leftTreeChangeable,
                    udfOnSelectRow:function(rowId,status){
                        if(currentModelName == "entropyevaluation"){
                            var transformType=$this.find('#' + rowId + '_bestdirection').val();
                            var policy = $this.find('#' + rowId + '_policy').val();
                            if((transformType == "0" || transformType == "1") && policy == "0"){
                                $this.find('#' + rowId + '_value').validatebox({readonly: true});
                                $this.find('#' + rowId + '_interval').validatebox({readonly: true});
                                $this.find('#' + rowId + '_value').attr("disabled","");
                                $this.find('#' + rowId + '_interval').attr("disabled","");
                            }
                            if((transformType == "0" || transformType == "1") && policy == "1"){
                                $this.find('#' + rowId + '_value').attr("placeholder", "0,100");
                                $this.find('#' + rowId + '_interval').validatebox({readonly: true});
                                $this.find('#' + rowId + '_interval').attr("disabled","");
                                $this.find('#' + rowId + '_value').removeAttr("disabled");
                            }
                            if(transformType == "2"){
                                $this.find('#' + rowId + '_value').unbind('input').on('input', function () {
                                    var value = $this.find('#' + rowId + '_value').val().split(",");
                                    if( value.length == 0 || ( value.length ==1 && value[0].trim() =='')){
                                        $this.find('#' + rowId + '_value').attr("placeholder", "0,100");
                                        $this.find('#' + rowId + '_interval').val('');
                                        $this.find('#' + rowId + '_interval').attr("placeholder","50");
                                        $this.find('#' + rowId + '_interval').validatebox({readonly: true});
                                        $this.find('#' + rowId + '_interval').attr("disabled","");
                                    }else if(value.length == 2 && isNumber(value[0]) && isNumber(value[1])){
                                        var getValue = (parseFloat(value[0].replace(/\s+/g,'')) + parseFloat(value[1].replace(/\s+/g,'')))/2;
                                        $this.find('#' + rowId + '_interval').val(parseFloat(getValue.toFixed(4)));
                                    }else{
                                        $this.find('#' + rowId + '_interval').attr("placeholder",'');
                                        $this.find('#' + rowId + '_interval').val('');
                                    }
                                });
                                $this.find('#' + rowId + '_interval').validatebox({readonly: true});
                                $this.find('#' + rowId + '_interval').attr("disabled","");
                                $this.find('#' + rowId + '_value').removeAttr("disabled");
                                if($this.find('#' + rowId + '_value').val() == ''){
                                    $this.find('#' + rowId + '_value').attr("placeholder", "0,100");
                                    $this.find('#' + rowId + '_interval').attr("placeholder","50");
                                    $this.find('#' + rowId + '_value').removeAttr("disabled");
                                    $this.find('#' + rowId + '_interval').removeAttr("disabled");
                                }
                            }
                            if(transformType == "3" && ($this.find('#' + rowId + '_value').val() == '' || $this.find('#' + rowId + '_interval').val() == '')){
                                $this.find('#' + rowId + '_value').attr("placeholder", "0,100");
                                $this.find('#' + rowId + '_interval').attr("placeholder","40,60");
                            }
                        }
                    },
                });
                thisZone.find("td[align=center]").css("width", "235px");
            } else {
                thisZone.grid_columns_selected_with_btn({
                    "width": width,
                    "height": height,
                    "pendingDiv": leftColumnSelect,
                    "contextMeta": metadata, //上下文字段信息列表
                    "udfContextColLabels": zoneParam.udfContextColLabels,
                    "contextHiddenColNames": contextHiddenColNames,//将字段名和类型隐藏
                    "rowsData": rowDatas,
                    "udfColLabels": udfColLabels,
                    "udfColsModel": udfColsModel,
                    "parentDialog": $this,
                    "fieldset": zoneParam.fieldset,
                    "allowTypes": allowTypes,
                    "gridMaxData": gridMaxData,
                    "uniquefield": uniquefield,//针对同一个字段进行处理
                    "removeDup": removeDup,
                    isRendercboxClass: true,
                    directToEdit: directToEdit,
                    multEdit: multEdit,
                    pagination: "variableselection_label" != zoneParam.id ? true : false,
                    showBtn: TempoMineUtils.canEdit(args.data.formEditable),
                    editable: TempoMineUtils.canEdit(args.data.formEditable),
                    defaultWidth: defaultWidth,
                    leftTreeChangeable: args.rightParams.leftTreeChangeable,
                    //保存节点名称(可选)
                    currentModelName:currentModelName,
                });
            }
            // 设置按钮居中显示,getOption("height")为列表内容高度，需加27(表头高度)，再减去22(按钮)，最后再除2
            thisZone.find(".tempo-mine-grid-columns-with-selbtn-btn").css({
                "margin-top": (height + 5) / 2.0,
                "margin-left": "15px"
            });
            //监听右侧grid变化事件
            var id = thisZone.find("table").eq(1).attr("id");
            var targetGridCompete = $("#" + id).jqGrid('getGridParam').gridComplete;

            $("#" + id).jqGrid('getGridParam').gridComplete = function () {
                //删除之后判断是否需要展示分类汇总的近似计算和精准计算
                if (args.currentModelName == "subtotal") {
                    var grid = args.zoneCache['subtotal_countCol'];
                    var newGridDate = grid.grid_columns_selected_with_btn("getAllEditOrDataFunction");
                    if (newGridDate && newGridDate.length > 0) {
                        var jisuanWay = $('input[name=subtotal-way-set]:checked').attr('id');
                        for (var i = 0; i < newGridDate.length; i++) {
                            var newCalcFunc = newGridDate[i].calcFunc;
                            if (newCalcFunc == "udfQuantile" || newCalcFunc == "median" ||
                                newCalcFunc == "upQuartile" || newCalcFunc == "downQuartile") {
                                $(".tempo-mine-dp-subtotal-right-bottom-radios").show();
                                $('#' + jisuanWay).radio({
                                    checked: true,
                                });
                                break;
                            }
                            $(".tempo-mine-dp-subtotal-right-bottom-radios").hide();
                            $('#approximate-subtotal').radio({
                                checked: true,
                            });
                        }
                    } else {
                        $(".tempo-mine-dp-subtotal-right-bottom-radios").hide();
                        $('#approximate-subtotal').radio({
                            checked: true,
                        });
                    }
                }
                Eventbus.triggerHandler(addPre("bindEvent"), args.zoneCache)[0];

                if (targetGridCompete) {
                    targetGridCompete.call($("#" + id));
                }
            }

        } else {
            if (zoneParam.height) {
                height = zoneParam.height;
            }
            // 设置div的高度
            $this.find("#" + zoneParam.id).height(height);
        }
        // 缓存当前对象grid_columns_selected_with_btn,若需要
        args.zoneCache[zoneParam.id] = thisZone;
        if (args.currentModelName == "subtotal") {
            callGridFunction("getGridTable", thisZone).datagrid({
                oneRowEdit: function (rowid) {
                    var calcFuncValue = $(this).children().find("tr[id='" + rowid + "']").find("select[id='" + rowid + "_calcFunc']").val();
                    var input = $(this).children().find("tr[id='" + rowid + "']").find("input[id='" + rowid + "_value']");
                    if (calcFuncValue == "udfQuantile") {
                        input.validatebox({readonly: false});
                        input.removeAttr("unselectable");
                    } else {
                        input.validatebox({readonly: true});
                        input.attr("unselectable", "on");
                    }
                }
            })
        }
    }

    /**
     * 添加当前模块的前缀
     */
    var addPre = function (labelKey) {
        if (currentModelName == "") {
            return labelKey;
        }
        return currentModelName + "." + labelKey;
    }

    /**
     * 完成配置界面的初始化功能
     */
    var initProperty = function () {
        // 页面初始化
        initDialog();
        // 初始化右侧缓存对象
        args.zoneCache = {};
        // 当前模块名称赋值
        currentModelName = args.currentModelName;
        currentModelParam = args.rightParams;
        // 初始化列操作区域，并赋值
        initColumnSelectZone();
        // 调用当前图标模块的初始化及赋值方法
        Eventbus.triggerHandler(addPre("initAndFillback"))[0];
        TempoMineUtils.disabledPropertyParam($this, args.data.formEditable);
    }

    /**
     * 调用初始化功能
     */
    initProperty();
});